﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Silvermoon.OpenGL;

namespace Silvermoon.Utils
{
    internal static class RectangleUtil
    {
        public static Rectangle Cut(Rectangle inner, Rectangle outer)
        {
            int l = inner.Left;
            int r = inner.Right;
            int t = inner.Top;
            int b = inner.Bottom;
            if (outer.Top > t) t = outer.Top;
            if (outer.Left > l) l = outer.Left;
            if (outer.Bottom < b) b = outer.Bottom;
            if (outer.Right < r) r = outer.Right;

            int w = r - l; if (w < 0) w = 0;
            int h = b - t; if (h < 0) h = 0;
            return new Rectangle(l, t, w, h);
        }

        public static Size MinSize(Size size)
        {
            int w = size.Width;
            int h = size.Height;
            if (w < 8) w = 8;
            if (h < 8) h = 8;

            size.Width = Texture.ConvertToValidTextureDimension(w);
            size.Height = Texture.ConvertToValidTextureDimension(h);

            return size;
        }
    }
}
